package com.hqully.smartfumehood.controller;


import com.github.pagehelper.PageInfo;
import com.hqully.smartfumehood.common.utils.ResultVoUtil;
import com.hqully.smartfumehood.common.vo.QueryVo;
import com.hqully.smartfumehood.common.vo.ResultVo;
import com.hqully.smartfumehood.entity.LabManager;
import com.hqully.smartfumehood.entity.dto.LabManagerDto;
import com.hqully.smartfumehood.service.LabManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lly
 * @since 2022-03-09
 */
@RestController
@RequestMapping("/api/lab-manager")
public class
LabManagerController extends BaseController{
    @Autowired
    private LabManagerService labManagerService;

    @PostMapping("/find-all-lab-manager")
    public ResultVo findAllLabManager(@RequestBody QueryVo queryVo){

        PageInfo<LabManager> allLabManager = labManagerService.findAllLabManager(queryVo);

        return ResultVoUtil.success(allLabManager);
    }

    @PostMapping("/add-lab-manager")
    public ResultVo addLabManager(@RequestBody LabManagerDto labManagerDto){
        try {
            int status = labManagerService.addLabManager(labManagerDto);
        } catch (DuplicateKeyException e) {
            return ResultVoUtil.error("该工号已存在");
        }


        return ResultVoUtil.success("添加实验室管理员成功");
    }

    @PostMapping("/delete-lab-manager")
    public ResultVo deleteLabManager(@RequestParam("tid") String tid){
        labManagerService.deleteLabManager(tid);

        return ResultVoUtil.success("删除实验室管理员成功");
    }

    @PostMapping("/update-lab-manager")
    public ResultVo updateLabManager(@RequestBody LabManagerDto labManagerDto){
        labManagerService.updateLabManager(labManagerDto);

        return ResultVoUtil.success("更新实验室管理员成功");
    }

}
